
<?php
/*include_once('init.php');*/
	if(!empty($_POST)) {
	/*	print_r($_POST);die;*/
		/*session_start();*/
		
		/*print_r($_FILES);die;*/
			$path='';
		if (!empty($_FILES['url']['name'][0])) {
		
			$urllist=array();
			foreach ($_FILES['url']['name'] as $key => $value) {
				$urllist[$key]['name']=$_FILES['url']['name'][$key];
				$urllist[$key]['type']=$_FILES['url']['type'][$key];
				$urllist[$key]['tmp_name']=$_FILES['url']['tmp_name'][$key];
				$urllist[$key]['error']=$_FILES['url']['error'][$key];
				$urllist[$key]['size']=$_FILES['url']['size'][$key];
				
			}
			foreach ($urllist as $key => $val) {
					$path= url($val);
			}
			/*print_r($urllist);die;*/

		
		};

			/*die;*/


		$where['title']=$_POST['title'];
		$where['cate_id']=$_POST['cate_id'];
		$where['url']=$path;
		$where['content']=$_POST['text'];
		$where['author']=$_POST['textarea'];
		
		
	
			
		$row=add('news',$where);
		/*print_r($row);die;*/
        if ($row>0) {
        	echo '<script>alert("添加成功");location.href="index.php?c=news&a=news&admin=1";</script>';

        }else{
        	echo '<script>alert("添加失败");history.go(-1);</script>';die;
        }
		

	}


		$id=!empty($_GET['id'])?$_GET['id']:'0';
	/*$sql = "select * from `cate` where `pid`='$id'";
	$result=mysqli_query($link,$sql);
	while ($arr=mysqli_fetch_assoc($result)) {
		$cate[]=$arr;
	}*/
		$cate=gatselect('cate',"`pid`=$id");

        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {

        
        	

        	echo json_encode($cate);die;
        	
        }
	include( VIEW_PATH.$admin.'layst.html');

?>
